<?php 
namespace app\Admin\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\captcha\Captcha;
use think\Cookie;
class Login extends Controller 
{
	/*登陆验证*/
	public function login(){
		if(request()->isPost()){
			$user_name = input('post.username');
			$user_pwd = input('post.password');
			$code = input('post.captcha');
			if(captcha_check($code)){
				$where = "user_name = '$user_name' and user_pwd ='$user_pwd'";
			 	$re = db('user')->where($where)->find();
			 	$userid = $re['user_id'];
				if($re){
					Cookie::set('userid',"$userid");
					Cookie::set('userid','$userid');
					$this->redirect('Index/index');
					$this->redirect('Index/index');
				}else{
					$this->error('账号或者密码错误');
				}
			}else{
				$this->error('验证码错误');
			}	
		}else{
			return $this->fetch();
		}
		
	}

	/*退出登陆*/
	public function login_out(){
		Cookie::delete('userid');
		$this->success('退出成功','Login/login','',1);
	}



}
